Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process configchange event and save the parameters in some data structure. #190

Merged
merged 14 commits into from
Mar 20, 2024

Conversation

yarkinwho
Copy link
Contributor

Resolve #186

The planned implementation is like this:

1 ship_receiver_plugin will check if it received a configchange event, if found, make sure it's the first related action in a block, save the new config in the resulting native_block/

2 block_conversion_plugin will make sure if there's a new config in the incoming native_block, it should be the first one native block for a resulting evm block. Then:
a save the new config in the resulting evm block
b change the evm block's consensus_parameter_index to it's own height.

3 blockchain_plugin will detect if there's new config coming in with the evm blocks. if so:
a save new parameters
b verify_chain for the blocks before if necessary

c insert the incoming blcok
d verify chain (may be not necessary)

-- EDIT: after some double thinking, we do not need this for blockchain_plugin, let's just try a normal process first.

src/channels.hpp Outdated
std::vector<native_trx> transactions;
};

struct consensus_parameter_event {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this structure used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to delete. deleted

@@ -19,6 +19,17 @@ struct evmtx_v0 {
using evmtx_type = std::variant<evmtx_v0>;
EOSIO_REFLECT(evmtx_v0, eos_evm_version, rlpx)

struct gas_parameter_data_v1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should replicate the types we have here until we have a place where to put all these interfaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, was copied from there back then. Didn't notice it was changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

.gas_sset = std::visit([](auto&& arg) -> auto& { return arg.gas_parameter.gas_sset; }, new_config),
}
});
curr.consensus_parameter_index = curr.header.number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should save here the consensus parameters to db

Comment on lines 50 to 78
if (new_block->consensus_parameter_index) {
if (*new_block->consensus_parameter_index == new_block->header.number) {
// Parameters updated in this block.
SILKWORM_ASSERT(new_block->consensus_parameters_cache.has_value());
update_consensus_parameters(exec_engine->get_tx(), new_block->header.number, *new_block->consensus_parameters_cache);
last_consensus_parameters = new_block->consensus_parameters_cache;
last_consensus_parameters_index = new_block->consensus_parameter_index;
}
else if (last_consensus_parameters_index && *last_consensus_parameters_index == *new_block->consensus_parameter_index) {
// Copy over parameters for last block.
SILKWORM_ASSERT(last_consensus_parameters.has_value());
new_block->consensus_parameters_cache = last_consensus_parameters;
} else {
// Parameter not cached, happen during startup or fork.
new_block->consensus_parameters_cache = read_consensus_parameters(exec_engine->get_tx(), *new_block->consensus_parameter_index);
// In such cases, the parameter MUST be in db.
SILKWORM_ASSERT(new_block->consensus_parameters_cache.has_value());

last_consensus_parameters_index = new_block->consensus_parameter_index;
last_consensus_parameters = new_block->consensus_parameters_cache;
}
}
else {
// Should only reach here if fork happens during version update.
// TODO: Add guards according to eosevm versions.
last_consensus_parameters_index = std::nullopt;
last_consensus_parameters = std::nullopt;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this and the last_consensus_parameters_index / last_consensus_parameters variables

Comment on lines 120 to 121
std::optional<silkworm::BlockNum> last_consensus_parameters_index;
std::optional<eosevm::ConsensusParameters> last_consensus_parameters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed

@iamphoumin852 iamphoumin852 requested review from taokayan and removed request for taokayan March 11, 2024 07:17
Copy link
Contributor

@elmato elmato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a last request, i think we should remove the consensus parameters previously added here, when we are reverting each of the forked native blocks here

We decided to store the hash of the ConsensusParameters values, so there is no need to remove it when a fork happens on the native side

@yarkinwho yarkinwho merged commit 6cb707a into main Mar 20, 2024
6 checks passed
@yarkinwho yarkinwho deleted the yarkin/process_config_change branch March 20, 2024 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Process configchange event to record minimum gas price and gas parameters
2 participants